package com.big.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.model.model.order.MerchandiseOrder;
import com.big.model.model.stock.MerchandiseStock;
import com.big.model.vo.stock.StockVo;
import com.big.stock.mapper.MerchandiseStockMapper;
import com.big.stock.service.MerchandiseStockService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.helpers.QuietWriter;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MerchandiseStockServiceImpl extends ServiceImpl<MerchandiseStockMapper, MerchandiseStock> implements MerchandiseStockService {

    /**
     *     改变库存-已售
     */
    @Override
    public Integer upStock(StockVo stockVo) {
        //已售
        Integer THIS_Sold = stockVo.getSSold();
        //数量
        Integer THIS_Num= stockVo.getSNum();
        UpdateWrapper<MerchandiseStock> updateWrap = new UpdateWrapper<>();
        if(!StringUtils.isEmpty(stockVo.getMId())
        &&!StringUtils.isEmpty(String.valueOf(stockVo.getSNum()))
        &&!StringUtils.isEmpty(String.valueOf(stockVo.getSSold()))){
        }

        updateWrap.eq("m_id",stockVo.getMId()).set("s_num",THIS_Num).set("s_sold",THIS_Sold);
        int update = baseMapper.update(null, updateWrap);
        return update;
    }




    /**
     *   查询库存
     */
    @Override
    public MerchandiseStock merchandiseStockInfo(String mId) {
        QueryWrapper<MerchandiseStock> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(String.valueOf(mId))){
            wrapper.eq("m_id",mId);
        }
        MerchandiseStock merchandiseStock = baseMapper.selectOne(wrapper);
        return merchandiseStock;
    }
}
